package com.dreamwhale.machinery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.entity.VipArticleCollect;
import com.dreamwhale.machinery.dao.VipArticleCollectMapper;
import com.dreamwhale.machinery.service.VipArticleCollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 资料库收藏表 服务实现类
 * </p>
 *
 * @author Author
 * @since 2020-06-05
 */
@Service
public class VipArticleCollectServiceImpl extends ServiceImpl<VipArticleCollectMapper, VipArticleCollect> implements VipArticleCollectService {

    @Resource
    private VipArticleCollectMapper vipArticleCollectMapper;

    @Override
    public List<VipArticleCollect> selectVipArticleCollects(Integer userId) {
        return vipArticleCollectMapper.selectVipArticleCollects(userId);
    }

    @Override
    public int selectVipArticleCollectCount(Integer id, Integer userId) {
        QueryWrapper<VipArticleCollect> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid", userId).eq("article_id", id);
        List<VipArticleCollect> list = vipArticleCollectMapper.selectList(queryWrapper);
        if (list.size() > 0) {
            return 1;
        }
        return 0;
    }
}
